package com.cet.mysdk.config;

import com.cet.mysdk.factory.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: cet-practice
 * @description:
 * @author: 陈恩涛
 * @create: 2023-06-12 23:00
 **/

@Configuration
@EnableConfigurationProperties(SqlSessionProperties.class)
public class SqlSessionAutoConfiguration {

    @Autowired
    private SqlSessionProperties sqlSessionProperties;

    @Bean
    @ConditionalOnMissingBean
    public SqlSessionFactory getSqlSessionFactory() {
        return new SqlSessionFactory(
            sqlSessionProperties.getUserName(),
            sqlSessionProperties.getPassword(),
            sqlSessionProperties.getDriver(),
            sqlSessionProperties.getUrl());
    }
}
